@echo off

setlocal
set execFile=%~1
set vbsFile=%temp%\yufei_runas_admin.vbs

if "%execFile%"=="" ( 
    echo no execute file set
    goto:eof
)
if not exist "%execFile%" ( 
    echo %execFile% not exist
    goto:eof
)

rem :: BatchGotAdmin
rem :-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
 
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )
 
:UACPrompt
    rem echo "/k ""%execFile%"" ""%~2"" ""%~3"" ""%~4"" ""%~5"" ""%~6"" ""%~7"" ""%~8"" ""%~9"""
    rem pause
    echo Set UAC = CreateObject^("Shell.Application"^) > "%vbsFile%"
    echo UAC.ShellExecute "cmd.exe", "/c %execFile% ""%~2"" ""%~3"" ""%~4"" ""%~5"" ""%~6"" ""%~7"" ""%~8"" ""%~9""", "%windir%\system32\", "runas", 1 >> "%vbsFile%"    
    "%vbsFile%"
    rem exit /B
    exit
 
:gotAdmin
    if exist "%vbsFile%" ( del "%vbsFile%" )
    pushd "%CD%"
    CD /D "%~dp0"
    exit

